<template>
  <!-- 常用流程 -->
  <div class="module" style="min-height: 265px;max-height: 400px;">
    <a-tabs default-active-key="1">
      <a-tab-pane key="1">
        <template slot="tab">{{$t('m.system.portlet.process.frequentlyProcess')}}<span>({{dataSource.length}})</span> </template>
        <div class="module-in">
          <div class="backlog">
            <a-row>
              <a-col :span="12" v-for="record in dataSource" style="padding-bottom: 14px;" :key="record.id">
                <ych-icon :type="record.icon || 'fork'" :style="{color: primaryColor}"/><a @click="handleStart(record.id)" style="padding-left: 5px;">{{record.name + "-v" + record.version}}</a>
              </a-col>
            </a-row>
          </div>
        </div>
      </a-tab-pane>
      <!-- 右侧图标 -->
      <template slot="tabBarExtraContent">
        <ych-icon type="sync" class="panel-icon" @click="loadData"/>
        <ych-icon type="more" class="panel-icon" @click="loadMore"/>
      </template>
    </a-tabs>
    <redirect-modal ref="startForm"></redirect-modal>
  </div>
</template>
<script>

  import { getAction,ReviewAndVerification} from '@/api/manage'
  import RedirectModal from '../../bpm/redirect/RedirectModal'
  import YchConstant from "@/api/YchConstant";
  import { mixin } from '@/utils/mixin.js'

  export default {
    name: 'CommonProcess',
    mixins: [mixin],
    components: {
      // 自定义图标
      RedirectModal
    },
    data: () => {
      return {
        loading: false,
        url:{
          list: YchConstant.PREFIX_EFORM + '/manage/actAppGroup/getCustomProcDefList'
        },
        dataSource:[],
      };
    },
    created () {
      this.loadData()
    }, 
    inject: ['addRouter'],
    methods: {
      loadData(){
        this.loading = true
        let that = this
        getAction(this.url.list, null).then(res => {
          if (res.success) {
            that.dataSource = res.result.customProcessList
          } else {
            this.messageUtil.warning(res.message)
          }
          this.loading = false
        })
      },
      handleStart (id) {
        let router = null
        if (this.$store.getters.formOpenType === '2') {
          router = this.addRouter({
            path: '/bpm/addFromProcess/' + id,
            component: resolve => require(['@/views/bpm/redirect/RedirectTab.vue'], resolve),
            props: {
              id: id,
              func: 'addFromProcess',
            },
            meta: {
              title: this.$t('m.system.portlet.process.startProcess'),
            }
          }, true);
          if (router) {
            this.$router.push(router).catch(err => {})
          }
        }
        if (!router) {
          this.$refs.startForm.addFromProcess(id)
        }
      },
      loadMore(){
        this.$router.push({
          path: '/process/startprocess'
        }).catch(err => {})
      },
    },
  };
</script>

<style lang="less">
  @import '~@/views/system/portlet/css/basicStyle.less';
</style>
